<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title></title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="${ctxPath}/static/manage/css/x-admin.css" media="all">
    <link rel="stylesheet" href="${ctxPath}/static/manage/layui/css/layui.css" media="all">
    <script src="${ctxPath}/static/manage/layui/layui.js"></script>
    <script src="${ctxPath}/static/manage/js/jquery-1.8.3.min.js"></script>
</head>
<body>
<div class="x-nav">
        <span class="nav-breadcrumb">
            <a><cite>后台管理></cite></a>
            <a><cite>管理列表></cite></a>
            <a><cite>类型列表</cite></a>
        </span>
</div>
<div class="x-body">
    <blockquote class="layui-elem-quote quoteBox">
        <div class="layui-inline">
            <div class="layui-input-inline">
                <input type="text" class="layui-input searchContent" placeholder="请输入文件名关键字"/>
            </div>
            <a class="layui-btn search_btn" data-type="reload">搜索</a>
        </div>
        <div class="layui-inline">
            <a class="layui-btn layui-btn-normal add_btn">添加</a>
        </div>
        <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right"
           href="javascript:location.replace(location.href);" title="刷新"><i class="layui-icon" style="line-height:30px">ဂ</i></a>
    </blockquote>
    <table id="downloadTable" lay-filter="downloadTable"></table>
</div>
</body>
</html>

<script type="text/javascript">
    layui.use(['jquery', 'table', 'layer', 'util'], function () {
        var $ = layui.$, table = layui.table, layer = layui.layer, util = layui.util;
        var active = {
            reload: function () {
                table.reload('search_table_id', {
                    where: {
                        content: $('.searchContent').val(),
                        page: 1
                    }
                });
            }
        };
        table.render({
            elem: '#downloadTable'
            , id: 'search_table_id'
            , height: 500
            , url: 'computer/findByCon'
            , page: true
            , limit: 10
            , limits: [10]
            , cols: [[
                {checkbox: true, fixed: true},
                {field: 'id', title: '序号', width: '6%', sort: true, fixed: true},
                {field: 'name', title: '名称', width: '16%', sort: true},
                {
                    field: 'tempId', title: '操作', width: '15%', templet: function (d) {
                        return '<a class="layui-btn layui-btn-xs" lay-event="update" lay-id="' + d.tempId + '">' +
                            '<i class="layui-icon layui-icon-edit"></i>修改</a>' +
                            '<a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="del" lay-id="' + d.tempId + '">' +
                            '<i class="layui-icon layui-icon-delete"></i>移除</a>';
                    }
                }
            ]]
        });
        // 搜索（利用定义的active重新载入表格）
        $('.search_btn').on('click', function () {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';

        });
        // 添加
        $('.add_btn').on('click', function () {
            layer.open({
                content: "添加内容",
                type: 2,
                fix: false, //不固定
                maxmin: true,
                area: ['600px', '450px'],
                content: "/manage/computer/addComputer",
                success: function (result) {
                    if (result == "处理成功") {
                        window.parent.location.reload();
                    }
                }
            });

        });
        // 监听工具条
        table.on('tool(downloadTable)', function (obj) {
            var data = obj.data, event = obj.event, tr = obj.tr;
            console.log(data);
            switch (event) {
                case "del":
                    layer.confirm('真的删除行么？', function (index) {
                        layer.close(index);
                        $.ajax({
                            type: 'post',
                            url: '/manage/computer/isDeleteComputer',
                            data: {'id': data.id},
                            success: function (res) {
                                if(res){
                                    alert("已经存在信息，无法删除")
                                }else{
                                $.ajax({
                                    type: 'post',
                                    url: '/manage/computer/deleteComputer',
                                    data: {'id': data.id},
                                    success: function (result) {
                                        alert(result);
                                        window.location.reload();    // 刷新
                                    }
                                });
                            }
                            }
                        });
                    });
                    break;
                // 修改
                case "update":
                    computerUpdate(data);
                    break;

                    //修改保存
                function computerUpdate(rowData) {
                    layer.open({
                        title: "修改信息",
                        type: 2,
                        fix: false, //不固定
                        maxmin: true,
                        area: ['400px', '400px'],
                        content: "/manage/computer/update/" + rowData.id,

                    });
                }
            }
        });
    });

</script>
